package cn.bdqn.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import cn.bdqn.dao.BaseDao;

/**
 * 读取配置文件
 * @author Administrator
 */
public class ConfigHandler {

	static ConfigHandler configHandler =null;
	Properties params = null;
	
	//私有化构造方法
	private ConfigHandler() {
		params=new Properties();
		String configFile = "database.properties";
		InputStream is=ConfigHandler.class.getClassLoader().getResourceAsStream(configFile);
		try {
			params.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 返回当前实例
	 * @return
	 */
	public static ConfigHandler getInstance() {
		if(configHandler==null) {
			configHandler = ConfigHandlerManage.configHandler;
		}
		return configHandler;
	}
	
	/**
	 * 根据key获取值
	 */
	public String getProperty(String key) {
		return params.getProperty(key);
	}
	
	/**
	 * configHandler初始化时不进行ConfigHandlerManage初始化
	 * @author Administrator
	 *
	 */
	public static class  ConfigHandlerManage {
		public static ConfigHandler configHandler = new ConfigHandler();
	}
	
	
}
